<template>
  <a-modal
    :visible="show"
    @cancel="modalClose"
    width="22.5rem"
    wrapClassName="confirm-modal"
    :footer="null"
    :centered="true"
    :destroyOnClose="true"
    :zIndex="2000"
    :closable="closable"
    :maskClosable="maskClosable"
  >
    <template v-if="html">
      <div class="content-html" v-html="msg"></div>
    </template>
    <template v-else>
      <div class="content">
        {{ msg }}
      </div>
    </template>
    <div v-if="type === 'confirm'" class="btn-group">
      <a-button type="primary" shape="round" @click="confirmClick">{{
        yesBtnText
      }}</a-button>
      <a-button type="primary" shape="round" @click="modalClose">{{
        noBtnText
      }}</a-button>
    </div>
    <div v-if="type === 'alert'" class="btn-group__alert">
      <a-button type="primary" block shape="round" @click="alertClick">{{
        alertBtnText
      }}</a-button>
    </div>
  </a-modal>
</template>
<script>
import { Modal } from "ant-design-vue";
export default {
  components: {
    AModal: Modal,
  },
  props: {
    title: {
      type: String,
      default: "提示",
    },
    msg: {
      type: String,
      default: "",
    },
    type: {
      type: String,
      default: "confirm",
    },
    alertBtnText: {
      type: String,
      default: "我知道了",
    },
    yesBtnText: {
      type: String,
      default: "确定",
    },
    noBtnText: {
      type: String,
      default: "取消",
    },
    hasMark: {
      type: Boolean,
      default: true,
    },
    html: {
      type: Boolean,
      default: false,
    },
    maskClosable: {
      type: Boolean,
      default: true
    },
    closable: {
      type: Boolean,
      default: true

    }
  },
  data() {
    return {
      promiseStatus: null,
      show: false,
    };
  },
  methods: {
    confirm() {
      let _this = this;
      this.show = true;
      return new Promise(function(resolve, reject) {
        _this.promiseStatus = { resolve, reject };
      });
    },
    modalClose() {
      this.show = false;
      this.promiseStatus && this.promiseStatus.reject();
    },
    confirmClick() {
      this.show = false;
      this.promiseStatus && this.promiseStatus.resolve();
    },
    alertClick() {
      this.show = false;
      this.promiseStatus && this.promiseStatus.resolve();
    },
  },
};
</script>

<style lang="less">
.confirm-modal {
  .content {
    padding-top: 60px;
    text-align: center;
    font-size: 24px;
    color: #333333;
  }
  .content-html {
    text-align: center;
    font-size: 24px;
    color: #333333;
  }
  .btn-group {
    display: flex;
    margin-top: 40px;
    justify-content: space-between;
    .ant-btn {
      min-width: 130px;
      height: 50px;
    }
  }
  .btn-group__alert {
    display: flex;
    margin-top: 40px;
    justify-content: center;
    .ant-btn {
      width: 100%;
      height: 50px;
    }
  }
}
</style>
